﻿#region Legal

// Jimmy Zimmerman
// Team Mongoose
//
// END USER LICENSE AGREEMENT
// IMPORTANT - READ THIS CAREFULLY:  This End User License Agreement is a legal agreement
// between you (either an individual, business entity, currently active identity of an
// individual with Multiple Personality Disorder, octopus overlord, or otherworldly entity),
// and Team Mongoose, for the enclosed, components.
//
// By reading this document and/or installing this product, you agree to be bound by the
// terms of this EULA.
//
// Team Mongoose owns all copyright, trade secret, trademark, trade wars,
// patent, portent, and potential rights to these components.  Team Mongoose
// grants you the right to deploy the enclosed components.
//
// If you agree to the terms of this EULA, a license to use these components is granted to you.
//
// If you should happen to benefit from the enclosed components, then you are legally and
// contractually bound to thank us for it. Send your regards to jimmyzimms@hotmail.com.
//
// OTHER RIGHTS AND LIMITATONS
// You may not reverse-engineer, decompile, decode, disassemble, psycho-analyze, or otherwise
// attempt to find hidden meanings between the lines of this EULA; unless, of course, you should
// happen to find some, and they are funny.
//
// You may not translate this EULA or any part of the components into Ancient Sumerian.
//
// THESE COMPONENTS ARE PROVIDED “AS-IS” WITHOUT WARRANTY OF ANY KIND. ANY USE OF THE COMPONENTS
// CONTAINED IS AT YOUR OWN RISK. TEAM MONGOOSE DISCLAIM ALL WARRANTIES, EITHER
// EXPRESS OR IMPLIED, WITH RESPECT TO THE ACCURRACY AND CORRECTNESS OF THE COMPONENTS CONTAINED
// HEREIN. TEAM MONGOOSE DOES NOT WARRANT THAT THE COMPONENTS ARE FLAWLESS.
//
// REDISTRIBUTION AND USE IN SOURCE AND BINARY FORMS, WITH OR WITHOUT MODIFICATION, ARE PERMITTED
// PROVIDED THAT THE FOLLOWING CONDITIONS ARE MET:
// * REDISTRIBUTIONS OF SOURCE CODE MUST RETAIN THE ABOVE COPYRIGHT NOTICE
// * REDISTRIBUTIONS IN BINARY FORM MUST NOTE THE USE OF THE COMPONENT IN DOCUMENTATION AND/OR
//   OTHER MATERIALS PROVIDED WITH THE DISTRIBUTION.
// * NEITHER THE NAME OF TEAM MONGOOSE MAY BE USED TO ENDORES OR PROMOTE PRODUCTS
//   DERIVED FROM THIS SOFTWARE WITHOUT SPECIFIC PRIOR WRITTEN PERMISSION.
//
// IN NO EVENT SHALL TEAM MONGOOSE BE HELD LIABLE FOR INCIDENTAL, SPECIAL, INDIRECT,
// INCONSEQUENTIAL, UNBELIEVABLE, EXAGGERATED, VERBOSE, OR TYPICAL DAMAGES INCURRED WHILE USING
// THE ENCLOSED COMPONENTS.
//
// OUR STUFF ALWAYS WORKS - SOMETIMES.

#endregion

using Microsoft.AnalysisServices.AdomdClient;
using System.Data.Common;

namespace System.Data.MdxClient
{
    /// <summary>
    /// Represents a parameter to a <see cref="MdxCommand"/> and optionally its mapping to <see cref="DataSet"/> columns.
    /// </summary>
    public class MdxParameter : DbParameter
    {
        #region Fields

        private readonly AdomdParameter parameter;

        #endregion

        #region Fields

        /// <summary>
        /// Gets the internal, native ADOMD.NET parameter.
        /// </summary>
        /// <value>An <see cref="AdomdParameter"/> object.</value>
        protected internal AdomdParameter AdomdParameter
        {
            get
            {
                return this.parameter;
            }
        }

        #endregion

        #region Overrides

        /// <summary>
        /// Gets or sets the type of the parameter.
        /// </summary>
        /// <value>One of the <see cref="DbType"/> values.</value>
        public override DbType DbType
        {
            get
            {
                return this.parameter.DbType;
            }
            set
            {
                this.parameter.DbType = value;
            }
        }

        /// <summary>
        /// Gets or sets a value that indicates whether the parameter is input-only, output-only,
        /// bidirectional, or a stored procedure return value parameter.
        /// </summary>
        /// <value>One of the <see cref="ParameterDirection"/> values.</value>
        public override ParameterDirection Direction
        {
            get
            {
                return this.parameter.Direction;
            }
            set
            {
                this.parameter.Direction = value;
            }
        }

        /// <summary>
        /// Gets or sets a value that indicates whether the parameter accepts null values.
        /// </summary>
        /// <value>True if null values are accepted; otherwise false.</value>
        public override bool IsNullable
        {
            get
            {
                return this.parameter.IsNullable;
            }
            set
            {
                this.parameter.IsNullable = value;
            }
        }

        /// <summary>
        /// Gets or sets the name of the parameter.
        /// </summary>
        /// <value>The parameter name.</value>
        public override string ParameterName
        {
            get
            {
                return this.parameter.ParameterName;
            }
            set
            {
                this.parameter.ParameterName = value;
            }
        }

        /// <summary>
        /// Resets the type associated with this <see cref="MdxParameter"/>.
        /// </summary>
        public override void ResetDbType()
        {
            // no implementation
        }

        /// <summary>
        /// Gets or sets the maximum size, in bytes, of the data within the column.
        /// </summary>
        /// <value>The maximum size, in bytes, of the data within the column. The default value is
        /// inferred from the parameter value.</value>
        public override int Size
        {
            get
            {
                return this.parameter.Size;
            }
            set
            {
                this.parameter.Size = value;
            }
        }

        /// <summary>
        /// Gets or sets the name of the source column mapped to the <see cref="DataSet"/> and used
        /// for loading or returning the <see cref="Value"/>.
        /// </summary>
        /// <value>The name of the source column mapped to the <see cref="DataSet"/>.
        /// The default is an empty string.</value>
        public override string SourceColumn
        {
            get
            {
                return this.parameter.SourceColumn;
            }
            set
            {
                this.parameter.SourceColumn = value;
            }
        }

        /// <summary>
        /// Gets or sets the <see cref="DataRowVersion"/> to use when you load <see cref="Value"/>.
        /// </summary>
        /// <value>One of the <see cref="Value"/> values. The default is <see cref="DataRowVersion.Current"/>.</value>
        public override DataRowVersion SourceVersion
        {
            get
            {
                return this.parameter.SourceVersion;
            }
            set
            {
                this.parameter.SourceVersion = value;
            }
        }

        /// <summary>
        /// Sets or gets a value which indicates whether the source column is nullable.
        /// </summary>
        /// <value>True if the source column is nullable; false if it is not. The default value is false.</value>
        public override bool SourceColumnNullMapping
        {
            get;
            set;
        } 

        /// <summary>
        /// Gets or sets the value of the parameter.
        /// </summary>
        /// <value>An <see cref="Object"/> that is the value of the parameter. The default value is null.</value>
        public override object Value
        {
            get
            {
                return this.parameter.Value;
            }
            set
            {
                this.parameter.Value = value;
            }
        }

        /// <summary>
        /// Returns a lifetime service object to maintain the lifetime of the component.
        /// </summary>
        /// <returns>A lifetime service object.</returns>
        public override object InitializeLifetimeService()
        {
            return this.parameter.InitializeLifetimeService();
        }

        #endregion

        #region Constructors

        internal MdxParameter( AdomdParameter parameter )
        {
            this.parameter = parameter;
        }

        /// <summary>
        /// Instantiates a new instance of the <see cref="MdxParameter"/> class.
        /// </summary>
        public MdxParameter()
            : this( new AdomdParameter() )
        {
        }

        /// <summary>
        /// Instantiates a new instance of the <see cref="MdxParameter"/> class.
        /// </summary>
        /// <param name="parameterName">The name of the parameter.</param>
        /// <param name="value">The value of the parameter.</param>
        public MdxParameter( string parameterName, object value )
            : this( new AdomdParameter( parameterName, value ) )
        {

        }

        #endregion
    }
}
